package com.zl.csMall.mine.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.csMall.mine.user.mapper.UserMapper;
import com.zl.csMall.mine.user.po.User;
import com.zl.csMall.mine.user.service.UserService;
import com.zl.csMall.util.Util;
import org.springframework.stereotype.Service;

/**
 * @description: UserServiceImpl
 * @author: ChenNing
 * @date 2025-10-15 12:00
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Override
    public User getByOpenId(String openId) {
        if (Util.isNullOrEmpty(openId)){
            return null;
        }
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getOpenId, openId);
        User user = this.getOne(queryWrapper);
        return user == null || user.getId() == 0 ? null : user;
    }

    @Override
    public User getByUsername(String username) {
        if (Util.isNullOrEmpty(username)){
            return null;
        }
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUsername, username);
        User user = this.getOne(queryWrapper);
        return user == null || user.getId() == 0 ? null : user;
    }

}
